package edu.nju.desserthouse.servlets;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.nju.desserthouse.action.business.ClerkInfoBean;
import edu.nju.desserthouse.dao.ClerkDao;
import edu.nju.desserthouse.dao.ShopDao;
/**
 * Servlet implementation class DeleteClerkServlet
 */

@WebServlet("/delete.technician")
public class DeleteClerkServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
    
	@EJB
	ClerkDao clerkDao;
	@EJB
	ShopDao shopDao;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteClerkServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		execute (request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		execute (request, response);
	}

	public void execute(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
		String delete_id = req.getParameter("delete_id");
		clerkDao.delete(delete_id);
		long num = shopDao.getShopNum();
		ClerkInfoBean clerks = new ClerkInfoBean();
		clerks.setClerkList(clerkDao.getClerkList());
		req.getSession().setAttribute("clerkInfo", clerks);
		req.getSession().setAttribute("shop_count", num);
		resp.sendRedirect("/desserthouseWEB/technician/clerkmanage.jsp");
	}
}
